1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : - Modulgruppe: News
5 : - Beschreibung: Haelt die Daten einer Kategorie aus der DB
6 : - Version: 1.0, 28/03/09
7 : - Autor(en): Christoph Thelen <christoph.thelen@mni.fh-giessen.de>
8 : +---------------------------------------------------------------------------+
9 : This program is free software; you can redistribute it and/or
10 : modify it under the terms of the GNU General Public License
11 : as published by the Free Software Foundation; either version 2
12 : of the License, or any later version.
13 : +---------------------------------------------------------------------------+
14 : This program is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU General Public License for more details.
18 : You should have received a copy of the GNU General Public License
19 : along with this program; if not, write to the Free Software
20 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 : +--------------------------------------------------------------------------*/
22 :
23 : class Category {
24 :
25 : private $id;
26 :
27 : private $position;
28 :
29 : private $color;
30 :
31 : private $visible;
32 :
33 : public static function create(array $order) {
34 15 : $result = array();
35 15 : foreach ($order as $position => $category) {
36 12 : $visible = $category['visible'] ? true : false;
37 12 : array_push($result, new self($category['id'], $position, $category['color'], $visible));
38 15 : }
39 15 : return $result;
40 : }
41 :
42 : public function __construct($id, $position, $color, $visible) {
43 24 : $this->id = $id;
44 24 : $this->position = $position;
45 24 : $this->color = $color;
46 24 : $this->visible = $visible;
47 24 : }
48 :
49 : public function getId() {
50 13 : return $this->id;
51 : }
52 :
53 : public function getPosition() {
54 9 : return $this->position;
55 : }
56 :
57 : public function getColor() {
58 9 : return $this->color;
59 : }
60 :
61 : public function isVisible() {
62 10 : return $this->visible;
63 : }
64 :
65 : public function hasDarkColor() {
66 5 : return ($this->color) ? $this->getBrightestColorValue() <= 0.65 : false;
67 : }
68 :
69 : public function getRgbColor() {
70 4 : if (! $this->color) return null;
71 :
72 4 : $r = substr($this->color, 0, 2);
73 4 : $g = substr($this->color, 2, 2);
74 4 : $b = substr($this->color, 4, 2);
75 4 : return array(hexdec($r), hexdec($g), hexdec($b));
76 : }
77 :
78 : private function getBrightestColorValue() {
79 4 : list($r, $g, $b) = $this->getRgbColor();
80 4 : $r /= 255;
81 4 : $g /= 255;
82 4 : $b /= 255;
83 4 : return max($r, $g, $b);
84 : }
|